//
//  LeadVC.m

//
//  Created by shui on 16/9/23.
//  Copyright © 2016年 shui. All rights reserved.
//

#import "LeadVC.h"
#import "TabBarVc.h"



//#import "YARootTabBarController.h"

#define SCREEN_W [UIScreen mainScreen].bounds.size.width
#define SCREEN_H [UIScreen mainScreen].bounds.size.height



@interface LeadVC ()<UIScrollViewDelegate,UIGestureRecognizerDelegate,UITabBarControllerDelegate>
{
    NSArray *_imageArr;
}
@property (strong, nonatomic)UIPageControl *pageControl;
@end

@implementation LeadVC

//-(BOOL)prefersStatusBarHidden
//{
//    return YES;
//}
//-(UIStatusBarStyle)preferredStatusBarStyle{
//    return UIStatusBarStyleLightContent;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    if (!ISP4) {
        _imageArr = @[@"lead6_1",@"lead6_2",@"lead6_3"];
    }else{
        _imageArr = @[@"lead4_1",@"lead4_2",@"lead4_3"];
    }
    //    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
    //    self.automaticallyAdjustsScrollViewInsets=NO;
    self.view.backgroundColor=[UIColor orangeColor];
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, SCREEN_W, self.view.frame.size.height+20)];
    scrollView.contentSize=CGSizeMake(SCREEN_W*(_imageArr.count+1), SCREEN_H);
    scrollView.pagingEnabled=NO;
    scrollView.userInteractionEnabled=YES;
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.delegate=self;
    [self.view addSubview:scrollView];
    
    
    for (int i=0; i<_imageArr.count; i++) {
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_W*i, 0, SCREEN_W, CGRectGetHeight(scrollView.frame))];
        imageView.image=[UIImage imageNamed:_imageArr[i]];
        [scrollView addSubview:imageView];
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 20)];
        view.backgroundColor=[UIColor whiteColor];
        [imageView addSubview:view];
        
        if (i == _imageArr.count - 1) {
            imageView.userInteractionEnabled = YES;
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
            btn.frame = CGRectMake(0, SCREEN_H - 80, 120, 30);
            btn.center = CGPointMake(self.view.center.x, btn.center.y);
            btn.backgroundColor = [UIColor clearColor];
            [btn setTitle:@"立即体验" forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(way) forControlEvents:UIControlEventTouchUpInside];
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
            btn.layer.cornerRadius =15.f;
            btn.layer.borderWidth =2.f;
            btn.layer.borderColor =[UIColor whiteColor].CGColor;
            btn.layer.masksToBounds =YES;
            
            [imageView addSubview:btn];
        }
    }
    _pageControl=[[UIPageControl alloc]init];
    _pageControl.center=CGPointMake(SCREEN_W/2, SCREEN_H-40);
    [self.view addSubview:_pageControl];
    _pageControl.numberOfPages=_imageArr.count;
    //当前原点颜色
    _pageControl.currentPageIndicatorTintColor= NavBackColor;
    //其他原点颜色
    _pageControl.pageIndicatorTintColor=[UIColor whiteColor];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    if (scrollView.contentOffset.x<0) {
        scrollView.contentOffset=CGPointMake(0, 0);
        scrollView.pagingEnabled=NO;
    }
    if (scrollView.contentOffset.x>10) {
        scrollView.pagingEnabled=YES;
    }
 
    if (scrollView.contentOffset.x > (_imageArr.count - 1) * SCREEN_W) {
        scrollView.contentOffset = CGPointMake((_imageArr.count - 1) * SCREEN_W, 0);
        scrollView.pagingEnabled = NO;
    }
    CGFloat scrollviewW =  scrollView.frame.size.width;
    CGFloat x = scrollView.contentOffset.x;
    int page = (x + scrollviewW / 2) /  scrollviewW;
    self.pageControl.currentPage = page;
}
-(void)way
{

    
    TabBarVc *mainVC=[[TabBarVc alloc]init];
    LogingViewController * loging =[[LogingViewController alloc]init];
    mainVC.delegate=self;
    UIView *lastView=[self.view snapshotViewAfterScreenUpdates:NO];
    lastView.frame=[UIScreen mainScreen].bounds;
    
    [mainVC.view addSubview:lastView];
    [mainVC.view bringSubviewToFront:lastView];
    [UIView animateWithDuration:2 animations:^{
        lastView.alpha=0;
    } completion:^(BOOL finished) {
        [lastView removeFromSuperview];
    }];
    
    //    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:mainVC];
    
    if (verifTokenAndEnter) {
        
        [UIApplication sharedApplication].keyWindow.rootViewController = mainVC;
        
    }else {
        
        [UIApplication sharedApplication].keyWindow.rootViewController = loging;
    }

    
}




@end
